﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SilkeyERP.Model.Repository
{
    public class SalePersonRepository : ISalePersonRepository
    {

        private bool disposed = false;
        private Model.SilkeyERPEntities context;

        public SalePersonRepository()
        {
            if (this.context == null)
            this.context = new SilkeyERPEntities();            
        }

        public IEnumerable<SalesPerson> GetAll()
        {
            return context.SalesPerson.ToList();
        }

        public SalesPerson GetByID(int ID)
        {
            return context.SalesPerson.Find(ID);
        }

        public void Insert(SalesPerson Obj)
        {
            context.SalesPerson.Add(Obj);
            Save();
        }

        public void Delete(int ID)
        {
            SalesPerson student = context.SalesPerson.Find(ID);
            context.SalesPerson.Remove(student);
            Save();
        }

        public void DeleteLogical(int ID)
        {
            SalesPerson Obj = GetByID(ID);
            //Obj.Enable = false;
            Update(Obj);
        }

        public void Update(SalesPerson Obj)
        {
            context.Entry(Obj).State = EntityState.Modified;
            Save();
        }

        public void Save()
        {
            context.SaveChanges();
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
                if (disposing)
                    context.Dispose();
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

    }
}
